package cn.gson.crm.control;

import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import cn.gson.crm.model.pojo.CareType;
import cn.gson.crm.model.pojo.CustomerCare;
import cn.gson.crm.model.pojo.Customerinfo;
import cn.gson.crm.service.LLJ_CustomerCareService;


@Controller
@SessionAttributes({"ccId","cc"})  
public class LLJ_CustomerCareController {
	@Autowired
	private LLJ_CustomerCareService customerCareService;
	   
	
	/*  选择客户信息   */
	@GetMapping("/getCustomerMessage") 
	@ResponseBody                          
	public List<Customerinfo> getCustomerMessage(){
		return customerCareService.serchAllCustomer();
	}   
	
	/* CustomerCare表 */
	/* 客户关怀表 */
	@GetMapping("/get_All_CustomerCare_page")    
	@ResponseBody 
	public Map get_All_CustomerCare_page(int page,int rows){
		List<CustomerCare> list=customerCareService.getAllCustomerCarePages(page, rows);
		System.out.println("输出数据：---------------------------");
		System.out.println(list);
		long count=customerCareService.count();   
		Map map=new HashMap<>();
		map.put("total", count);                  
		map.put("rows", list);
		
		return map; 
	}
	
	/* CustomerCare表 */  
	/* 1-通过客户关怀表'主题'查询 (无分页显示) */
	@GetMapping("/get_CustomerCare_page_byTheme")
	@ResponseBody          
	public List<CustomerCare> get_CustomerCare_page_byTheme(String key){
		System.out.println("输出查询主题---------------");
		System.out.println(key);
		
		List<CustomerCare> list=customerCareService.getAllCustomerCarePagesByTheme(key);
		System.out.println(list);
		System.out.println("-------------------");
		return list;   
		
	}
	
	/* CustomerCare表 */
	/* 2-添加客户关怀数据 */ 
	@PostMapping("/addCustomerCanoneata") 
	@ResponseBody        
	public String add_CustomerCare_data(CustomerCare cc){
		System.out.println("进入新增---------------------------"); 
		System.out.println("输出新增id："+cc.getCcId());        
		System.out.println("ccTheme:"+cc.getCcTheme());
		System.out.println("customerName:"+cc.getCustomerName());
		System.out.println("ccLinkMan:"+cc.getCcLinkMan());
		System.out.println("ccCreationTime:"+cc.getCcCreationTime());  
		System.out.println("ccExecutor:"+cc.getCcExecutor());
		System.out.println("ccContent:"+cc.getCcContent());  
		System.out.println("ccFeedback:"+cc.getCcFeedback());  
		
		if(customerCareService.addOne_data_CustomerCare(cc)){
			return "success";  
		}else{
			return "failed";    
		}
	}          
	
	
	/* CustomerCare表 */
	/* 3-编辑客户关怀数据  */
	@PostMapping("/editCustomerCanoneata")  
	@ResponseBody   
	public String edit_CustomerCare_data(CustomerCare cc){
		System.out.println("进入编辑---------------------------"); 
		System.out.println("输出编辑id："+cc.getCcId());     
		System.out.println("ccTheme:"+cc.getCcTheme());
		System.out.println("customerName:"+cc.getCustomerName());
		System.out.println("ccLinkMan:"+cc.getCcLinkMan());
		System.out.println("ccCreationTime:"+cc.getCcCreationTime());  
		System.out.println("ccExecutor:"+cc.getCcExecutor());
		System.out.println("ccContent:"+cc.getCcContent());  
		System.out.println("ccFeedback:"+cc.getCcFeedback());          
		if(customerCareService.editData(cc)){
			return "success";
		}else{
			return "failed";   
		}    
	}     
	
	/* CustomerCare表 */
	/* 5-通过客户关怀id删除数据 */
	@GetMapping("/delete_CustomerCare")   
	@ResponseBody     
	public String delete_CustomerCare(Long CC_id) throws Exception{
		System.out.println("开始进入删除---------------------------------");
		System.out.println("输出Long ccId："+CC_id); 
		
		if(customerCareService.deleteOneDate(CC_id)){
			return "success"; 
		}else{
			return "failed";  
		}   
	} 
	
	/*  批量删除  */
	@GetMapping("/careDeleteMoreData")
	@ResponseBody
	public String careDeleteMoreData(String strIds){
		String id[]=strIds.split(",");
		try {  
			for(int i=0;i<id.length;i++){
				Long deleteId=(long) Integer.parseInt(id[i]);
				customerCareService.deleteOneDate(deleteId); 
			}
		} catch (Exception e) {
			return e.getMessage();     
		}
		return "success";
		
	}
	/* 通过id查询客户关怀信息  */
	@RequestMapping("/getCustorByid")
	@ResponseBody
	public CustomerCare getCustorByid(Long ccId){   
		System.out.println("-------------------输出--------------------");
		System.out.println("--------------"+ccId);      
		CustomerCare cus=new CustomerCare();
		cus=customerCareService.getCustomerData(ccId);  
		  
		return cus;    
	}
	
	/* CustomerCare表 */
	/* 客户关怀类型表 */
	@PostMapping("/find_Care_type_data")
	@ResponseBody  
	public List<CareType> find_Care_type_data(){
		System.out.println(customerCareService.findCareTypeData());     
		return customerCareService.findCareTypeData();   
	}
}
